<!--

    Copyright © 2016-2025 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<section class="tb-form-panel">
  <mat-expansion-panel class="tb-settings" expanded>
    <mat-expansion-panel-header>
      {{ 'widgets.maps.map-action.map-action-buttons' | translate }}
    </mat-expansion-panel-header>
    <ng-template matExpansionPanelContent>
      <div class="tb-form-table overflow-y-auto">
        <div class="tb-form-table-header no-padding-right">
          <div class="tb-form-table-header-cell min-w-32" style="flex: 1 1 40%" translate>widgets.maps.map-action.label</div>
          <div class="tb-form-table-header-cell w-10 min-w-10" translate>widgets.maps.map-action.icon</div>
          <div class="tb-form-table-header-cell w-10 min-w-10" translate>widgets.maps.map-action.color</div>
          <div class="tb-form-table-header-cell min-w-32" style="flex: 1 1 60%" translate>widgets.maps.map-action.action</div>
          <div class="tb-form-table-header-cell w-20 min-w-20 xs:w-10 xs:min-w-10"></div>
        </div>
        <div class="tb-form-table-body" cdkDropList cdkDropListOrientation="vertical"
             [cdkDropListDisabled]="!dragEnabled"
             (cdkDropListDropped)="buttonDrop($event)">
          @for (mapAction of mapActionButtonsForm.controls; track mapAction) {
            <div cdkDrag [cdkDragDisabled]="!dragEnabled" class="tb-draggable-form-table-row">
              <tb-map-action-button-row class="flex-1"
                                        [formControl]="mapAction"
                                        (buttonRemoved)="removeButton($event)">
              </tb-map-action-button-row>
              <div class="tb-form-table-row-cell-buttons">
                <button class="xs:!hidden"
                        [class.tb-hidden]="!dragEnabled"
                        mat-icon-button
                        type="button"
                        cdkDragHandle
                        matTooltip="{{ 'action.drag' | translate }}"
                        matTooltipPosition="above">
                  <mat-icon>drag_indicator</mat-icon>
                </button>
              </div>
            </div>
          } @empty {
            <span class="tb-prompt flex items-center justify-center">{{ 'widgets.maps.map-action.no-action-buttons-configured' | translate }}</span>
          }
        </div>
      </div>
      <button type="button" mat-stroked-button color="primary" class="max-w-fit" (click)="addButton()">
        {{ 'widgets.maps.map-action.add-button' | translate }}
      </button>
    </ng-template>
  </mat-expansion-panel>
</section>
